<template>
  <div>
    <van-nav-bar title="登录"></van-nav-bar>

    <van-form style="margin-top: 50px;" @submit="onSubmit">
      <van-field v-model="form.username" placeholder="请输入用户名" name="" label="用户名："
                 :rules="[{required:true}]"></van-field>
      <van-field v-model="form.password" placeholder="请输入密码" name="" label="密码："
                 :rules="[{required:true}]" type="password"></van-field>

      <div style="margin: 16px;">
        <van-button round block type="info" :loading="false" @click="">
          登录
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {common} from "../../request/api";

export default {
  name: "Login",
  data() {
    return {form: {}};
  },
  created() {

  },
  methods: {
    async onSubmit(values) {
      const res = await common.login(this.form);
      if (res.data.code != 1) return false;

      this.$notify({type: 'success', message: res.data.msg});
      localStorage.setItem('ba_user', JSON.stringify(res.data.data));
      localStorage.setItem('ba_user_token', res.data.data.login_token);

      this.$router.push('/user');
    },
  },
}
</script>

<style scoped>

</style>
